<?php

namespace app\sysuser\controller;

use app\common\controller\SysBackend;
use app\common\service\ConfigService;
use app\common\service\UploadService;
use ba\Exception;

/**
 * 配置
 */
class Config extends SysBackend
{
    protected array $noNeedLogin = ['*'];

    protected array $noNeedPermission = ['*'];

    public function initialize(): void
    {
        parent::initialize();
    }


    /**
     * 查询配置JSON格式
     * @return void
     */
    public function listConfigJson(): void
    {
        $keys = $this->request->get('keys');
        $ConfigService = new ConfigService();
        $data = $ConfigService->getSysConfigValueList($keys);
        $this->ok(__('Operation completed'), $data);
    }

    public function getFavicon()
    {
        $ConfigService = new ConfigService();
        $data = $ConfigService->getSysConfigValue('logo');
        $uploadService = new UploadService();
        $bytes = $uploadService->downloadBody($data);
        try {
            header('Content-Type: image/*');
            echo $bytes;
            flush();
        } catch (Exception $e) {
            $this->fail($e->getMessage());
        }
    }

}